# 创建字典

dict1 = {"name":"kk","age":90}

# print(dict1)

# 增
dict1["name"] = 10
# print(dict1)

ret = dict1.setdefault("age",30)        # 不修改原有值，增加值
ret1 = dict1.setdefault("hobby","girl")
# print(ret)
# print(ret1)
# print(dict1)

# 查

# print(dict1["age"])
# print(type(dict1.keys()))     # 打印所有的键 类型 dict_keys
# print(list(dict1.keys()))     # 可转换成列表
# print(dict1.values())
# print(dict1.items())        # 元组

dict2 = {"1":"111","2":"222","age":89}
dict1.update(dict2)      # 同 键值 覆盖
# print(dict1)
# print(dict2)

# 删
# del dict1["name"]
# dict1.clear()
ret3 = dict1.pop("age")

# 随机删
d = dict1.popitem()

# print(ret3, dict1, d)


# 其他
# dict.fromkeys()

# 字典嵌套

av_catalog = {
    "欧美":{
        "www.youporn.com": ["很多免费的,世界最大的","质量一般"],
        "www.pornhub.com": ["很多免费的,也很大","质量比yourporn高点"],
        "letmedothistoyou.com": ["多是自拍,高质量图片很多","资源不多,更新慢"],
        "x-art.com":["质量很高,真的很高","全部收费,屌比请绕过"]
    },
    "日韩":{
        "tokyo-hot":["质量怎样不清楚,个人已经不喜欢日韩范了","听说是收费的"]
    },
    "大陆":{
        "1024":["全部免费,真好,好人一生平安","服务器在国外,慢"]
    }
}

av_catalog["大陆"]["1024"][1] += ",可以用爬虫爬下来"
# print(av_catalog["大陆"]["1024"])
av_catalog["欧美"]["www.youporn.com"][1] = "高清无码"
# print(av_catalog["欧美"]["www.youporn.com"])

# 排序
dic={5:'555',2:'222',4:'444'}
# print(sorted(dic))
# print(sorted(dic.values()))

# 遍历
dic5={'name': 'alex', 'age': 18}
 
for i in dic5:
    print(i,dic5[i])
 
for items in dic5.items():
    print(items)
for keys,values in dic5.items():
    print(keys,values)